# coding: utf-8
from urllib import parse,request
import requests
import json
import urllib.request as urlrequest

headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0',

    }

# 联众查询点数
def lianzhongInfo(url,softwareId,softwareSecret,username,password):-
    data = {
        'username': username,
        'password': password,
        'softwareId': softwareId,
        'softwareSecret': softwareSecret,
    }
    data = json.dumps(data).encode(encoding='utf-8')
    req = request.Request(url=url,data=data,headers=headers)
    res = request.urlopen(req)
    res = res.read().decode(encoding='utf-8')
    res = json.loads(res)
    try:
        recv_data = res["data"]
        availablePoints = recv_data['availablePoints']
        userPoints = recv_data['userPoints']
        return (availablePoints,userPoints)
    except:
        pass

# 滴滴查询点数
def ddInfo(url,secretkey):
    data = {
        'wtype': 'querypoint',
        'secretkey': secretkey,
    }
    req = requests.post(url=url,data=data,headers=headers)
    res = req.text
    res = json.loads(res)
    status = res['status']
    user_point = res['user_point']
    return (status, user_point)

# 极安查询点数
def jaInfo(url, count, pwd):
    try:
        url = url.replace('账户',count)
        url = url.replace('密码',pwd)
        response = urlrequest.urlopen(url).read()
        res = str(response,encoding='utf-8')
        if(res != "error"):
            token = res.split("||")[0]
            score = res.split("||")[1]
            return (token,score)
        else:
            return ("none","none")
    except:
        return False

# 魔云查询点数
def myInfo(url,username,password,dev_id):
    data = {
        'user': username,
        'pass': password,
        'dev_id': dev_id,
        'act':"login",
    }
    req = requests.post(url=url,data=data,headers=headers)
    res = req.text
    res = json.loads(res)
    status = res['code']
    if(status == 1):
        data = res['data']
        token = data['token']
        score = data['bp']
        return (status, token, score)
    else:
        return (101,"none","none")